import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '@/views/layout'
import Home from '@/views/layout/home'
import Category from '@/views/layout/category'
import Cart from '@/views/layout/cart'
import User from '@/views/layout/user'

const Login = () => import('@/views/login')
const Search = () => import('@/views/search')
const SearchList = () => import('@/views/search/list')
const Detail = () => import('@/views/detail')
const Pay = () => import('@/views/pay')
const Order = () => import('@/views/order')
const Address = () => import('@/views/address')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home',
    component: Layout,
    children: [
      {
        path: '/home',
        component: Home
      },
      {
        path: '/category',
        component: Category
      },
      {
        path: '/cart',
        component: Cart
      },
      {
        path: '/user',
        component: User
      }
    ]
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/searchlist',
    component: SearchList
  },
  {
    path: '/detail/:id',
    component: Detail
  },
  {
    path: '/pay',
    component: Pay
  },
  {
    path: '/order',
    component: Order
  },
  {
    path: '/address',
    component: Address
  }
]

const router = new VueRouter({
  routes
})

export default router
